﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MLY.Reports.DataReports
{
    public partial class OtdYieldReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (SessParam.IsClient)
                    ReportGrid.Columns[0].Visible = false;
                else
                    ReportGrid.Columns[1].Visible = false;
                
                ProductDDL.Items.Add(new ListItem("All products", "All products"));
                List<string> products = MLY.Bll.ReportsGenerator.GetOrganizationProducts(SessParam.OrganizationId, SessParam.IsClient);
                foreach (string s in products) ProductDDL.Items.Add(new ListItem(s, s));
                ProductDDL.SelectedValue = "All products";


                OtdYieldDataSource.SelectParameters.Add("OrganizationId", SessParam.OrganizationId.ToString());
                OtdYieldDataSource.SelectParameters.Add("IsClient", SessParam.IsClient ? "1" : "0");
                OtdYieldDataSource.SelectParameters.Add("Product", "All products");
            }
        }

        protected void Refresh(object sender, EventArgs e)
        {
            OtdYieldDataSource.SelectParameters["Product"].DefaultValue = ProductDDL.SelectedValue;
            ReportGrid.DataBind();
        }

        protected void btnXlsExport_Click(object sender, EventArgs e)
        {
            Response.Clear();
            gridExport.WriteXlsToResponse();

        }
        protected void btnXlsxExport_Click(object sender, EventArgs e)
        {
            Response.Clear();
            gridExport.WriteXlsxToResponse();
        }
        protected void btnRtfExport_Click(object sender, EventArgs e)
        {
            Response.Clear();
            gridExport.WriteRtfToResponse();
        }
        protected void btnCsvExport_Click(object sender, EventArgs e)
        {
            gridExport.WriteCsvToResponse();
        }
    }
}
